Executable program creation device, executable program creation method, and executable program creation program

ABSTRACT

An executable program creation unit performs lexical-syntactical analysis to generate an intermediate representation from source code, using a compiler program. The executable program creation unit extracts function call processing included in the intermediate representation. The executable program creation unit evaluates a function replacement condition set for the function call processing and corresponding to characteristics of a device controlled by the executable program. The executable program creation unit replaces the function call processing according to a function replacement rule if the function replacement condition is satisfied. The executable program creation unit intermediately generates a relocatable object using the replaced function call processing.

TECHNICAL FIELD

The present invention relates to a technology of creating an executableprogram to be executed by an industrial controller.

RELATED ART

At present, various systems that include an industrial controller tocontrol a plurality of devices (appliances) are put to practical use.For example, a system disclosed in Non-Patent Document 1 includes anindustrial controller (a machine automation controller) that isconnected to various devices via a control network. Moreover, theindustrial controller is connectable to an executable program creationdevice, such as a personal computer.

Software for creating an executable program is installed on the personalcomputer. Using this software, a programmer creates source code as thesource of the executable program. The building of the source codecreates the executable program. The executable program created using thepersonal computer is transferred to the industrial controller.

The industrial controller stores the executable program transferred fromthe personal computer. The industrial controller executes thisexecutable program to perform device control, such as setting of controlparameters of various devices.

RELATED ART DOCUMENTS Patent Documents

-   Non-Patent Document 1: Machine Automation Controller Overview on    Control Equipment of Omron, on the Internet:    http://www.fa.omron.co.jp/guide/technicalguide/454/270/index.html

SUMMARY OF THE INVENTION Problem to be Solved by the Invention

However, the devices connected to the industrial controller may havecharacteristics affecting the executable program. For this reason, theprogrammer needs to create a source file corresponding to suchcharacteristics.

For example, suppose that the device is changed from device A to deviceB and that device A and device B have different characteristics. In thiscase, the programmer needs to rewrite the source code corresponding todevice A into source code corresponding to device B and rebuild thesource code.

In view of this, it is an object of the present invention to provide atechnology for creating an executable program corresponding tocharacteristics of a device by using source code having less dependenceon the characteristics of the device.

Means for Solving the Problems

An executable program creation device according to the present inventionincludes a storage unit and an arithmetic unit. The storage unit storesa compiler program for compiling source code. The arithmetic unitcreates an executable program by intermediately generating a relocatableobject that is based on the source code, including execution of thecompiler program.

The arithmetic unit performs lexical-syntactical analysis to generate anintermediate representation from the source code, using the compilerprogram. The arithmetic unit extracts function call processing includedin the intermediate representation. The arithmetic unit evaluates afunction replacement condition set for the function call processing andcorresponding to characteristics of a device controlled by theexecutable program. The arithmetic unit replaces the function callprocessing according to a function replacement rule if the functionreplacement condition is satisfied. The arithmetic unit intermediatelygenerates a relocatable object using the replaced function callprocessing.

With this configuration, the executable program including an appropriatefunction corresponding to the characteristics of the device isautomatically created.

Effects of the Invention

According to the present invention, an executable program correspondingto characteristics of a device can be created while a burden on aprogrammer is reduced.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a schematic diagram illustrating a configuration of a systemin which an executable program according to an embodiment of the presentinvention is executed.

FIG. 2 is a diagram illustrating a configuration of an executableprogram creation device according to an embodiment of the presentinvention.

FIG. 3 is a diagram illustrating a data structure of a device variabletable.

FIG. 4 is a diagram showing a data structure of a function replacementrule table.

FIG. 5 is a flowchart illustrating a method for creating a library asthe source of a function replacement rule table.

FIG. 6 is a flowchart illustrating main processing of a method forcreating an executable program according to an embodiment of the presentinvention.

FIG. 7 is a flowchart illustrating compilation processing with afunction replacement rule.

FIG. 8 is a flowchart illustrating processing of function callreplacement.

FIG. 9 is a flowchart showing individual processing.

FIG. 10 is a diagram illustrating an example of a data structure of alibrary in data-type-based replacement processing.

FIG. 11 is a diagram illustrating an example of a data structure of alibrary in endianness-based replacement processing.

EMBODIMENTS OF THE INVENTION

A technology for creating an executable program according to anembodiment of the present embodiment is described, with reference to theaccompanying drawings. FIG. 1 is a schematic diagram showing aconfiguration of a system in which an executable program according tothe embodiment of the present invention is executed. FIG. 2 is a diagramshowing a configuration of an executable program creation deviceaccording to the embodiment of the present invention.

A system in which the executable program according to the presentembodiment is used is described first, with reference to FIG. 1. To bemore specific, a system 90 shown in FIG. 1 is an FA (Factory Automation)system. The system 90 includes an industrial controller 910, devices 921and 922, and a network 900.

As shown in FIG. 1, the industrial controller 910, the device 921, andthe device 922 are connected to each other via the network 900. Thedevices 921 and 922 include motion equipment, such as a motor, and acontrol unit controlling an operation of the motion equipment. Thedevices 921 and 922 are not limited to this, and may be any device thatincludes a predetermined operation unit and a control unit controllingan operation of the predetermined operation unit.

Moreover, the industrial controller 910 is connectable to a personalcomputer 10, as shown in FIG. 1. The executable program executed by theindustrial controller 910 is created by the personal computer 10. Theindustrial controller 910 downloads and stores the executable programcreated by the personal computer 10. It should be noted that theindustrial controller 910 stores a device variable table describedlater. The industrial controller 910 and the personal computer 10 storethe same device variable table.

By executing the executable program with reference to the devicevariable table, the industrial controller 910 controls the devices 921and 922 connected to the industrial controller 910 via the network 900.The device variable table is described in detail later.

As shown in FIG. 2, the personal computer 10 includes an executableprogram creation unit 11, an operation input unit 12, a communicationcontrol unit 13, and a display unit 14. The operation input unit 12 is,for example, a mouse and a keyboard. The display unit 14 is, forexample, a liquid crystal display. The communication control unit 13performs control to communicate with the industrial controller 910. Viathis communication control unit 13, the industrial controller 910downloads the executable program.

The executable program creation unit 11 corresponds to the executableprogram creation device according to the present invention, and includesa CPU 111 and a storage unit 112. The storage unit 112 stores variousprograms, tables, and so forth. To be more specific, the storage unit112 stores a compiler 21, a library manager 22, a device variable table23, a program editor 24, a function replacement rule editor 25. Thecompiler 21 stores a lexical-syntactical analyzer 211, a functionreplacer 212, a code generator 213, an assembler 214, and a functionreplacement rule table 215.

The CPU 111 corresponds to the arithmetic unit according to the presentinvention, and executes a program stored in the storage unit 112 tocreate the executable program. In doing so, the CPU 111 creates theexecutable program by reference to a necessary table.

For example, the program editor 24 writes and edits source code as thesource of the executable program. An editing screen of the programeditor 24 is displayed on the display unit 14 on which, for example,source code and various commands inputted from the operation input unit12 are displayed.

The function replacement rule editor 25 writes and edits a dummyfunction, a replacement function, and a function replacement ruledescribed later, for example. The dummy function, the replacementfunction, and the function replacement rule are stored in a library (notshown) included in the storage unit 112. The library manager 22 managesvarious kinds of data stored in the library. Storage information on thedummy function, the replacement function, and the function replacementrule are registered in the library manager 22.

It should be noted that, as described in JIS 3503: 2016 (IEC 61131-3),which is the programming language standard for programmable controllers,a “function” as used in the present specification is a “language elementwhich, when executed, typically yields one data element result andpossibly additional output variables.” A function is a structural unitused for program management and includes information on, for example,the name of the function, an argument variable group, a return valuevariable, and code representing processing including functions andprocedures. Through a function call, a function allows the processing tobe called to a different location of the program to be executed.

The device variable table 23 stores variables and attributes for eachdevice, for example. To be more specific, the device variable table 23has a data structure as shown in FIG. 3. FIG. 3 is a diagram showing thedata structure of the device variable table. The device variable table23 stores the devices included in the system 90 in association withvariables and attributes of the respective device. The number ofdevices, the number of variables, and the number of attributes are setin accordance with the device. Examples of the attribute include datatype and endianness. In example shown in FIG. 3, device A has variablesA1 and A2, and variable A1 has the attributes data type A11 andendianness A12, for example.

Generally speaking, the compiler 21 compiles the source code and createsa relocatable object. The lexical-syntactical analyzer 211 creates anintermediate representation IR from the source code. The functionreplacer 212 extracts function call processing included in theintermediate representation IR. By reference to the function replacementrule table 215, the function replacer 212 determines whether a functionreplacement condition is satisfied. If the function replacementcondition is satisfied, the function replacer 212 replaces the functioncall processing according to the function replacement rule.

Here, the function replacement rule table 215 stores the functionreplacement rules stored in the library via the library manager 22 onthe basis of the intermediate representation IR. FIG. 4 is a diagramshowing the data structure of the function replacement rule table. Thefunction replacement rule table 215 stores the function call processingextracted from the intermediate representation IR and the functionreplacement rules. In the example shown in FIG. 4, FUNC1, which issubjected to the function call processing, is stored in association withFUNC1 replacement rule 1 (replacement rule 11) and FUNC2 replacementrule (replacement rule 12), for example.

The code generator 213 creates code using the intermediaterepresentation IR including the replacement function call processing.The assembler 214 creates a relocatable object from the generated code.

Here, the dummy function, the replacement function, and the functionreplacement rule are previously set on the basis of the details in thedevice variable table 23, that is, the characteristics of variables ofthe device.

Thus, by the execution of the above processing by the compiler 21, thefunction call included in the intermediate representation IR calls anappropriate replacement function corresponding to the devicecharacteristics. With this, even when the programmer creates the sourcecode without consideration of the device characteristics, therelocatable object is appropriate in view of the device characteristics.Then, using this relocatable object, an appropriate executable programcorresponding to the device characteristics is created. Moreover, whenthe device is changed and thus the device characteristics are alsochanged, the industrial controller 910 transmits, to a post-changedevice (i.e. the changed device), a control command corresponding to thecharacteristics of this post-change device. In other words, even whenthe device is changed, the source code does not need to be rewritten.

Next, further specific processing of creating the executable program isdescribed.

First, processing of creating a library as the source of the functionreplacement rule table used during compilation is described. FIG. 5 is aflowchart showing a method for creating a library as the source of thefunction replacement rule table.

As shown in FIG. 5, the executable program creation unit 11 receives adescription of a dummy function (S101). The executable program creationunit 11 receives a description of a replacement function (S102). Theexecutable program creation unit 11 receives a description of a functionreplacement rule (S103). The executable program creation unit 11 storesthe dummy function, the replacement function, and the functionreplacement rule into the library, and registers the dummy function, thereplacement function, and the function replacement rule in the librarymanager 22 (S104).

FIG. 6 is a flowchart showing main processing of the method for creatingthe executable program according to the present embodiment of thepresent invention.

As shown in FIG. 6, the executable program creation unit 11 receives adescription of source code (S11). After receiving the description ofsource code, the executable program creation unit 11 receives a buildinstruction (S12).

When receiving the build instruction, the executable program creationunit 11 performs compile processing with a function replacement rule onthe source code (S13). As a result, a relocatable object is created.

The executable program creation unit 11 performs link processing on therelocatable object (S14). As a result, an executable program is created.

Next, specific processing of compilation processing with a functionreplacement rule is described. FIG. 7 is a flowchart of compilationprocessing with a function replacement rule.

The executable program creation unit 11 performs a lexical-syntacticalanalysis on the source code (S21). The source code is written by theprogrammer using the dummy function. By the execution of thelexical-syntactical analysis, an intermediate representation IR iscreated.

The executable program creation unit 11 extracts each function callprocessing included in the intermediate representation IR. Theexecutable program creation unit 11 detects whether a functionreplacement rule is given for each function included the intermediaterepresentation IR. Then, the executable program creation unit 11extracts the given function replacement rule and registers this functionreplacement rule in the function replacement rule table 215. In doingso, the executable program creation unit 11 registers the dummy functionand the replacement function in the function replacement rule table 215together with the function replacement rule.

The executable program creation unit 11 performs replacement of thefunction call (S23). The processing of function call replacement isdescribed with reference to FIG. 8 later.

The executable program creation unit 11 creates code using theintermediate representation IR obtained after the processing of functioncall replacement (that is, the intermediate representation IR using thereplacement function) (S24). Then, the executable program creation unit11 assembles the code (S25). As a result, a relocatable object iscreated.

Next, specific processing of function call replacement is described.FIG. 8 is a flowchart showing processing of function call replacement.

If the processing is not yet completed for all the function callsincluded in the intermediate representation IR, the executable programcreation unit 11 changes the function call subjected to the replacementprocessing (S31: NO→S32).

The executable program creation unit 11 performs the individualprocessing on the function call subjected to the replacement processing(S33). The individual processing is described with reference to FIG. 9.

If the processing is completed for all the function calls included inthe intermediate representation IR, the executable program creation unit11 ends the processing of function call replacement.

Next, specific individual processing is described. FIG. 9 is a flowchartshowing the individual processing.

The executable program creation unit 11 detects whether the function ofthe function call subjected to the processing (i.e., the functionsubjected to the processing) is registered in the function replacementrule table 215. More specifically, the executable program creation unit11 detects whether the function corresponds to one of FUNC1, FUNC2 . . .shown in FIG. 4.

If the function subjected to the processing is not registered in thefunction replacement rule table 215 (S41: NO), the executable programcreation unit 11 ends the processing without performing the replacementprocessing on this function call. If the function subjected to theprocessing is registered in the function replacement rule table 215(S41: YES), the executable program creation unit 11 proceeds to stepS42.

In step S42, the executable program creation unit 11 obtains, from thefunction replacement rule table 215, a function replacement conditiongroup corresponding to the function subjected to the processing. Forinstance, in the example shown in FIG. 4, when detecting that thefunction subjected to the processing is FUNC1, the executable programcreation unit 11 obtains the replacement rule 11 and the replacementrule 12.

Next, the executable program creation unit 11 evaluates the functionreplacement condition. To be more specific, the executable programcreation unit 11 detects whether the function replacement condition issatisfied.

If the function replacement condition is satisfied (S43: YES), theexecutable program creation unit 11 replaces the function call (S44). Ifthe function replacement condition is not satisfied (S43: NO), theexecutable program creation unit 11 does not replace the function callcorresponding to this condition.

If evaluation is not completed for all the function replacementconditions (S45: NO), the executable program creation unit 11 repeatsthe evaluation. On the other hand, if evaluation is completed for allthe function replacement conditions (S45: YES), the executable programcreation unit 11 ends the individual processing.

The processing described thus far allows an appropriate executableprogram corresponding to the device characteristics to be automaticallycreated without the need for the programmer to consider the devicecharacteristics when writing the source code, as described above.

Next, specific examples are described with reference to FIG. 10 and FIG.11. FIG. 10 is a diagram showing an example of a data structure of alibrary in data-type-based replacement processing. FIG. 11 is a diagramshowing an example of a data structure of a library in endianness-basedreplacement processing. In FIG. 10 and FIG. 11, the device is a controldevice for a motor. Moreover, in FIG. 10 and FIG. 11, the program ofeach function is indicated in ladder notation.

Example of Data Type

As shown in FIG. 10, for the data-type-based replacement processing, thelibrary stores “FUNCTION (Motor 32)”, “FUNCTION (Motor 64)”, “FUNCTION(Motor) (Dummy)”, and the replacement rules. The library stores“FUNCTION (Motor 32)” having Parameter 1 of DWORD type and Parameter 2of REAL type. Moreover, the library stores “FUNCTION (Motor 64)” havingParameter 1 of LWORD type and Parameter 2 of LREAL type. Furthermore,“FUNCTION (Motor)” (Dummy) has the same program structure as FUNCTION(Motor 32) and “FUNCTION (Motor 64)”, but no data type is designated.

In the replacement rules, the name of the function is stored inassociation with the condition (replacement condition) and processing.For example, the replacement rules state that if “Parameter 1=DWORDtype” and “Parameter 2=REAL type” is given as the replacement condition,then “FUNCTION (Motor)” is replaced by “FUNCTION (Motor 32)” as theprocessing. Moreover, the replacement rules state that if “Parameter1=LWORD type” and “Parameter 2=LREAL type” is given as the replacementcondition, then “FUNCTION (Motor)” is replaced by “FUNCTION (Motor 64)”as the processing.

In this way, when detecting the call of “FUNCTION (Motor)” in theintermediate representation IR, the executable program creation unit 11creates a relocatable object in which the call of “FUNCTION (Motor 32)”is executed if “Parameter 1=DWORD type” and “Parameter 2=REAL type” isgiven and in which the call of “FUNCTION (Motor 64)” is executed when“Parameter 1=LWORD type” and “Parameter 2=LREAL type” is given. Then,the industrial controller 910 executes the executable program includingthis relocatable object.

Example of Endianness

As shown in FIG. 11, for the endianness-based replacement processing,the library stores “FUNCTION (SWAP)”, “FUNCTION (MOVE)”, “FUNCTION (TLE)(Dummy)”, and the replacement rules. “FUNCTION (SWAP)” is a so-calledSWAP function. “FUNCTION (MOVE)” is a so-called MOVE function. “FUNCTION(TLE) (Dummy)” is a dummy program for endianness conversion.

In the replacement rules, the name of the function is stored inassociation with the condition (replacement condition) and processing.For example, the replacement rules state that if “input=Big” is given asthe replacement condition, then “FUNCTION (TLE)” is replaced by“FUNCTION (SWAP)” as the processing. Moreover, the replacement rulesstate that if “input=Little” is given as the replacement condition, then“FUNCTION (TLE)” is replaced by “FUNCTION (Move)” as the processing.

In this way, when detecting the call of “FUNCTION (TLE)” in theintermediate representation IR, the executable program creation unit 11creates a relocatable object in which the call of “FUNCTION (SWAP)” isexecuted if “input=Big” is given and in which the call of “FUNCTION(Move)” is executed if “input=Little” is given. Then, the industrialcontroller 910 executes the executable program including thisrelocatable object.

As described thus far, the configuration, the method, and the programaccording to the present embodiment allows an executable program that isappropriate for the device controlled by the executable program to beautomatically created without the need for the programmer to considerthe device characteristics, such as data type or endianness, whenwriting the source code.

INDEX TO THE REFERENCE NUMERALS

10 . . . personal computer, 11 . . . executable program creation unit,12 . . . operation input unit, 13 . . . communication control unit, 14 .. . display unit, 21 . . . compiler, 22 . . . library manager, 23 . . .device variable table, 24 . . . program editor, 25 . . . functionreplacement rule editor, 90 . . . system, 111 . . . CPU, 112 . . .storage unit, 211 . . . lexical-syntactical analyzer, 212 . . . functionreplacer, 212 . . . replacer, 213 . . . code generator, 214 . . .assembler, 215 . . . function replacement rule table, 900 . . . network,910 . . . industrial controller, 921 . . . device, 922 . . . device

1. An executable program creation device comprising: a memory storing acompiler program for compiling source code; and an arithmetic unitconfigured to create an executable program by intermediately generatinga relocatable object that is based on the source code, includingexecution of the compiler program, wherein the arithmetic unit isconfigured to, using the compiler program, perform operationscomprising: performing lexical-syntactical analysis to generate anintermediate representation from the source code; extracting functioncall processing included in the intermediate representation; replacingthe extracted function call processing in accordance with a functionreplacement rule if a function replacement condition set correspondingto characteristics of a device controlled by the executable program issatisfied; and intermediately generating the relocatable object usingthe replaced function call processing.
 2. The executable programcreation device according to claim 1, wherein the compiler programstored in the memory comprises a function replacement rule tablecomprising the function replacement condition, and the arithmetic unitis configured to perform operations further comprising evaluating thefunction replacement condition if a function subjected to callprocessing corresponds to the function replacement condition stored inthe function replacement rule table.
 3. The executable program creationdevice according to claim 1, wherein the memory stores a functionlibrary, and the function library comprises: a dummy function used forthe source code; and a plurality of replacement functions correspondingto the dummy function.
 4. An executable program creation method forcreating an executable program by intermediately generating arelocatable object based on the source code, including compilation ofsource code, the executable program creation method comprising:performing lexical-syntactical analysis to generate an intermediaterepresentation from the source code; evaluating a function replacementcondition corresponding to function call processing included in theintermediate representation; replacing the extracted function callprocessing according to a function replacement rule if the functionreplacement condition is satisfied; and intermediately generating therelocatable object using the replaced function call processing.
 5. Anon-transitory computer-readable recording medium storing an executableprogram creation program causing a computer to execute processing ofcreating an executable program by intermediately generating arelocatable object that includes compilation of source code and that isbased on the source code, the executable program creation program, whichwhen read and executed by the computer, causes the computer to performoperations comprising: performing lexical-syntactical analysis togenerate an intermediate representation from the source code; evaluatinga function replacement condition corresponding to function callprocessing included in the intermediate representation; replacing theextracted function call processing according to a function replacementrule if the function replacement condition is satisfied; andintermediately generating the relocatable object using the replacedfunction call processing.
 6. The executable program creation deviceaccording to claim 2, wherein the memory stores a function library, andthe function library comprises: a dummy function used for the sourcecode; and a plurality of replacement functions corresponding to thedummy function.